package cn.wolfcode.web.controller;

import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProduct;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.service.ISeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lanxw
 * 秒杀商品信息查询
 */
@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;

    /**
     * 进行压测，500个线程
     * 10次请求
     *  465    qps
     *  redis优化
     *  4600 qps起步
     * @param time
     * @return
     */
    @GetMapping("/queryByTime")
    public Result<List<SeckillProductVo>> getSeckillByTime(Integer time){
//          查询秒杀数据的商品
        List<SeckillProductVo> list= seckillProductService.getSeckillProductByTimeFromCache(time);
        return  Result.success(list);
    }

    /**
     * 进行压测，500个线程
     *      * 10次请求
     *      1500  qps
     *     redis优化之后 4930起步
     * @param time
     * @param seckillId
     * @return
     */
    @RequestMapping("/find")
    public Result<SeckillProductVo> getSeckillByTimeAndId(Integer time,Long seckillId){
//          查询秒杀数据的商品
        SeckillProductVo vo= seckillProductService.findFromCache(time,seckillId);
        return  Result.success(vo);
    }
}
